<?php

namespace app\api\controller\spike;

use app\api\BaseController;
use app\api\service\SpikeGoodsService;

class GoodsController extends BaseController
{
    /**
     * 获取秒杀商品
     * */
    public function index()
    {
        $spike_session_id = $this->request->param('spike_session_id/d');

        if (empty($spike_session_id)){
            return json(['code' => 0, 'msg' => '非法参数!']);
        }

        $spikeGoodsList = SpikeGoodsService::getSpikeGoodsList($spike_session_id);

        return json(['code' => 1, 'data' => $spikeGoodsList,'msg' => '请求成功!']);
    }

    /**
     *
     * 秒杀商品详情
     * */

    public function read()
    {
        $spike_goods_id = $this->request->param('spike_goods_id/d');

        if (empty($spike_goods_id)){
            return json(['code' => 0, 'msg' => '非法参数!']);
        }

        $spikeGoodsList = SpikeGoodsService::findSpikeGoods($spike_goods_id);

        return json(['code' => 1, 'data' => $spikeGoodsList,'msg' => '请求成功!']);
    }
}